package com.android.equipment.adapter;

import android.annotation.SuppressLint;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.android.equipment.R;
import com.android.equipment.dao.Device;
import com.android.equipment.dao.DeviceModel;
import com.android.equipment.dao.operate.DaoDevice;
import com.android.equipment.dao.operate.DaoDeviceModel;
import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

public class DeviceManagerAdapter extends BaseQuickAdapter<Device, BaseViewHolder> {
    public DeviceManagerAdapter(int layoutResId) {
        super(layoutResId);
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(@NonNull BaseViewHolder holder, Device device) {
        holder.setText(R.id.tv_device_name,device.getDeviceName());
        holder.setText(R.id.tv_device_code, device.getDeviceCode());
        DeviceModel deviceModel = DaoDeviceModel.getInstance().getDeviceModel(device.getDeviceModelId());
        holder.setText(R.id.tv_device_model, deviceModel.getDeviceModel()+"("+deviceModel.getModelCode()+")");

        holder.setText(R.id.tv_create_time, device.getCreateTime());
        TextView tvUpdateTime = holder.getView(R.id.tv_update_time);
        if (!StringUtils.isEmpty(device.getUpdateTime())){
            tvUpdateTime.setVisibility(View.VISIBLE);
            tvUpdateTime.setText(device.getUpdateTime());
        }else {
            tvUpdateTime.setVisibility(View.GONE);
        }


    }
}
